#include "Cylinder.h"
#include "Camera.h"

Cylinder::Cylinder(double radius, double height, const QString &name) :
    Item(name)
{
    //Ici, on ne designe pas les deux face dessus et dessous
    // degrees between two points around the cylinder
    double spacing = 30.0;

    /* FIXME complete the code */
    double theta, rTheta;

    //O est le centre cylinder
    double H = height/2.0;

    //le debut de cylinder
    double rPhi1 = M_PI/2.0 - atan(radius/H);

    //la fin de cylinder
    double rPhi2 = -M_PI/2.0 + atan(radius/H);

    //Pour diminuer les calcul
    //on tourne vector X selon Y avant
    Vector vy0 = Matrix::rotationY(rPhi1)*Vector::ORTHO_X;
    Vector vy1 = Matrix::rotationY(rPhi2)*Vector::ORTHO_X;

    Face face(Face::TriangleStrip);
    for (theta = 0.0; theta <= 360; theta += spacing) {
        rTheta = theta / 180.0 * M_PI;

        //Compte vector normal
        Vector n0 = Matrix::rotationZ(rTheta) * vy0;
        Vector n1 = Matrix::rotationZ(rTheta) * vy1;

        //Compte les coordinate
        Vector v0 = n0 * radius;
        Vector v1 = n1 * radius;

        //Ajout des points pour la face
        face.addPoint(v0, n0);
        face.addPoint(v1, n1);
    }
    addFace(face);
    /* STOP here */
}



